package org.javaboy.vhr.controller.emp;

import org.javaboy.vhr.model.Employee;
import org.javaboy.vhr.model.Employeeec;
import org.javaboy.vhr.service.EmployeeecService;
import org.javaboy.vhr.vo.EmpEcVo;
import org.javaboy.vhr.vo.RespBean;
import org.javaboy.vhr.vo.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/employee/ec")
public class EmpEcController {

    @Autowired
    EmployeeecService employeeecService;  //员工奖惩

    @GetMapping("/")
    public RespPageBean getEmployeeecByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, Employeeec employeeec, Date[] beginDateScope) {
        return employeeecService.getEmployeeecByPage(page, size, employeeec,beginDateScope);
    }

    @GetMapping("/getTotalEmployee")
    public RespBean getTotalEmployee(){
        List<Employee> employees = employeeecService.getTotalEmployee();
        //就因为ok这个静态方法，导致返回的是一个RespBean对象！前端接受的是一个对象！
        if(employees != null) {
           return  RespBean.ok("操作成功",employees);
        }else
            return RespBean.error("操作失败");
    }

    @PostMapping("/add")
    public RespBean add(@RequestBody Employeeec ec){
        Integer i = employeeecService.add(ec);
        if(i == null) {
            return RespBean.error("操作失败");
        }else return RespBean.ok("操作成功");
    }

    @PutMapping("/update")
    public RespBean updateEmp(@RequestBody Employeeec employeeec) {
        int result = employeeecService.update(employeeec);
        if(result==0) return RespBean.error("操作失败");
        else return RespBean.ok("操作成功");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteEcById(@PathVariable Integer id) {
        int result = employeeecService.delete(id);
        if(result==0) return RespBean.error("操作失败");
        else return RespBean.ok("操作成功");
    }
}